import * as Cesium from 'cesium/Cesium'


function PolygonPrimitive(e) {
    e = Cesium.defaultValue(e, Cesium.defaultValue.EMPTY_OBJECT),
        this.show = Cesium.defaultValue(e.show, !0);
    var t = Cesium.Color.clone(Cesium.defaultValue(e.color, Cesium.Color.WHITE));
    this._id = Cesium.createGuid(),
        this._color = t,
        this._depthFailColor = t,
        this._positions = [],
        this._boundingSphere = new Cesium.BoundingSphere,
        this._primitive = void 0,
        this._update = !0
}
Cesium.defineProperties(PolygonPrimitive.prototype, {
    positions: {
        get: function() {
            return this._positions
        },
        set: function(e) {
            this._positions = e,
                this._update = !0
        }
    },
    color: {
        get: function() {
            return this._color
        }
    },
    boundingVolume: {
        get: function() {
            return this._boundingSphere
        }
    }
}),
    PolygonPrimitive.prototype.update = function(e) {
        if (this.show) {
            var t = this._positions;
            if (t.length < 3)
                this._primitive = this._primitive && this._primitive.destroy();
            else {
                if (this._update) {
                    this._update = !1,
                        this._primitive = this._primitive && this._primitive.destroy();
                    var i = Cesium.CoplanarPolygonGeometry.fromPositions({
                        positions: t,
                        vertexFormat: Cesium.PerInstanceColorAppearance.FLAT_VERTEX_FORMAT
                    });
                    this._primitive = new Cesium.Primitive({
                        geometryInstances: new Cesium.GeometryInstance({
                            geometry: i,
                            attributes: {
                                color: Cesium.ColorGeometryInstanceAttribute.fromColor(this._color),
                                depthFailColor: Cesium.ColorGeometryInstanceAttribute.fromColor(this._depthFailColor)
                            },
                            id: this._id
                        }),
                        appearance: new Cesium.PerInstanceColorAppearance({
                            flat: !0,
                            closed: !1,
                            translucent: this._color.alpha < 1
                        }),
                        depthFailAppearance: new Cesium.PerInstanceColorAppearance({
                            flat: !0,
                            closed: !1,
                            translucent: this._depthFailColor.alpha < 1
                        }),
                        allowPicking: !1,
                        asynchronous: !1
                    }),
                        this._boundingSphere = Cesium.BoundingSphere.fromPoints(t, this._boundingSphere)
                }
                this._primitive.update(e)
            }
        }
    }
    ,
    PolygonPrimitive.prototype.isDestroyed = function() {
        return !1
    }
    ,
    PolygonPrimitive.prototype.destroy = function() {
        return this._primitive = this._primitive && this._primitive.destroy(),
            Cesium.destroyObject(this)
    };

export default PolygonPrimitive;